package com.leyou.item.mapper;

import com.leyou.item.pojo.Brand;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.additional.idlist.SelectByIdListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface BrandMapper extends Mapper<Brand>, SelectByIdListMapper<Brand,Long> {

    /**
     * 新增商品分类和品牌中间表数据
     * @param cid
     * @param bid
     */
    @Insert("insert into tb_category_brand (category_id,brand_id) values (#{cid},#{bid})")
    void insertCategoryBrand(@Param("cid") Long cid, @Param("bid")Long bid);

    /**
     * 根据bid删除tb_category_brand表数据
     * @param bid
     */
    @Delete("delete from tb_category_brand where brand_id=#{bid}")
    void deleteByBrandIdInCategoryBrand(Long bid);


    /**
     * 根据cid查询品牌
     * @param cid
     * @return
     */
    @Select("select * from tb_brand where id in (select brand_id from tb_category_brand where category_id=#{cid})")
    List<Brand> queryBrandByCategoryId(@Param("cid") Long cid);



}